package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.*;
import com.zzyl.nursing.dto.OrdersBody;
import com.zzyl.nursing.service.OrdersMemberService;
import com.zzyl.nursing.service.OrdersReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member")
@Api(tags = "护理项目查询")
public class OrdersMemberController {

    @Autowired
    private OrdersMemberService oms;
    @Autowired
    private OrdersReservationService ors;
    @GetMapping("/orders/project/page")
    @ApiOperation("根据参数分页查询护理项目")
    public TableDataInfo<NursingProject> OrdersMemberList(OrdersBody ob){
        return oms.OrdersMemberList(ob);

    }
    @GetMapping("/orders/project/{id}")
    @ApiOperation("根据ID查询护理项目")
    public R<NursingProject> getProjectById(@PathVariable("id") Long id){
        return R.restResult(oms.getById(id),200,"操作成功");
    }

    @GetMapping("/reservation/cancelled-count")
    @ApiOperation("根据当天取消预约数量")
    public R<Long> getCancelledCount(){
        return R.restResult(ors.getCancelledCount(),200,"操作成功");
    }
    @GetMapping("/reservation/countByTime")
    @ApiOperation("根据时间查询剩余预约数量")
    public R<List<Reservation>> countByTime(@RequestParam("time") Long time){
        return R.restResult(ors.countByTime(time),200,"操作成功");
    }
    @PostMapping("/reservation")
    @ApiOperation("新增预约")
    public R<Reservation> addReservation(@RequestBody Reservation reservation){
        if(ors.saved(reservation)){
            return R.fail(200,"操作成功");
        }
        return R.fail("操作失败");
    }
    @GetMapping("/reservation/page")
    @ApiOperation("分页查询预约")
    public R<TableDataInfo<Reservation>> reservationList(OrdersBody ob){
        return R.restResult(ors.reservationList(ob),200,"操作成功");
    }
    @PutMapping("/reservation/{id}/cancel")
    @ApiOperation("取消预约")
    public R<Reservation> cancelReservation(@PathVariable("id") Long id){
        if(ors.ubi(id)){
            return R.fail(200,"操作成功");
        }
        return R.fail("操作失败");
    }
    }
